			// 控制加载策略
			var quick;
			var user;
			var index;
			var pictures;
			var lh = "localhost:8080";
			$(function() {
				
				
				// 展示时间,延迟好看但影响实用性
				setInterval("showTime()", 1000);
				timeToLoad();
				// 可拖动的时间框
				$("#nyr").draggable();
				$("#sfm").draggable();

				// 获取用户信息
				$.post("http://"+lh+"/time/user_myTime.action", function(data) {
					// 给时间附加书签
					$("#a").wrap("<a href=" + data.user.bbs[0].bs[0].url + " target=_blank ></a>");
					$("#b").wrap("<a href=" + data.user.bbs[0].bs[1].url + " target=_blank ></a>");
					$("#c").wrap("<a href=" + data.user.bbs[0].bs[2].url + " target=_blank ></a>");
					$("#d").wrap("<a href=" + data.user.bbs[0].bs[3].url + " target=_blank ></a>");
					$("#e").wrap("<a href=" + data.user.bbs[0].bs[4].url + " target=_blank ></a>");
					$("#f").wrap("<a href=" + data.user.bbs[0].bs[5].url + " target=_blank ></a>");
					
					// v1书签盒子的名字		v2每一个链接		v3最后生成的盒子内容
					$.each(data.user.bbs, function(index, bb) {
						var v1 = bb.bbname;
						var v2 = '';
						
						$.each(bb.bs, function(index, b) {
							if (v1 == '时间书签') {
								
								v2 += '' +
									'<li>' +
									"<a href=" + b.url + " target=_blank ><span id="+ b.id +" class=timeB >" + b.bname + "</span></a>" +
								'</li>';
								
								return true; // 跳出本次循环
							}
							
							v2 += '' +
								'<li>' +
								"<a href=" + b.url + " target=_blank ><span id="+ b.id +" >" + b.bname + "</span></a>" +
								'</li>';
						});
						// 时间书签只需要修改功能,不给menuSpan	Id;
						if(v1 == '时间书签') {
							
							var v3 = '' +
								"<li class='nav-item' id=" + v1 + ">" +
								"<a href='javascript:;' ><i class='my-icon nav-icon icon_2'></i><span >" + v1 + "</span><i class='my-icon nav-more'></i></a>" +
								'<ul>' +
								v2 +
								'</ul>' +
								'</li>';

							$("#ulBody").append(v3);
						} else {

							var v3 = '' +
								"<li class='nav-item' id=" + v1 + ">" +
								"<a href='javascript:;' ><i class='my-icon nav-icon icon_3'></i><span id="+ bb.id +"_box>" + v1 + "</span><i class='my-icon nav-more'></i></a>" +
								'<ul>' +
								'<li>' +
								'<a  onclick="addBookMark($(this))" style="cursor: pointer;" ><span>添加书签</span></a>' +
								'</li>' +
								v2 +
								'</ul>' +
								'</li>';

							$("#ulBody").append(v3);
						}

					});

					// 排除自加载的
					$('.nav-item>a:gt(1)').on('click', function() {
						if(!$('.nav').hasClass('nav-mini')) {
							if($(this).next().css('display') == "none") {
								//展开未展开
								$('.nav-item').children('ul').slideUp(300);
								$(this).next('ul').slideDown(300);
								$(this).parent('li').addClass('nav-show').siblings('li').removeClass('nav-show');
							} else {
								//收缩已展开
								$(this).next('ul').slideUp(300);
								$('.nav-item.nav-show').removeClass('nav-show');
							}
						}
					});

					// 用户当前使用的图库
					user = data.user;
					pictures = data.user.pictures.split('-----');
					
					// 背景图片加载完成前使用过渡界面
					var eqimg = new Image();
					
					// 刚切图来的,没有喜欢的,未登录的看第一张
					var flag = getUrlParam("goAndSee");
					if(flag != null || user.prefer == "" || user.username=='admin') {
						eqimg.src = pictures[0];
						interim(eqimg);
							
						// 看喜欢的
					} else {
						eqimg.src = user.prefer;
						interim(eqimg);
					}
					
					// 为背景更换做准备
					var tempb = eqimg.src;
					var bg = tempb.substring(tempb.length - 29, tempb.length-2).replace(');','');
					index = myInArray(pictures, bg);
					
				}) ;
				
				let _menuItems = [

					{
						type: "title",
						text: "Modifica"
					},
					{
						type: "item",
						icon: "clone",
						text: "编辑",
						key: "copy",
						action: function(){
							if (loginCheck() != "login") {
								return;
							}
							
							// 获取鼠标右键下的span元素	em是鼠标右键时获取的鼠标下元素做成了成员变量在两个js文件中流转
							// 有时候鼠标点不住这个span,往下找一下就行
							var menuSpan;
							if (em.attr('id') == undefined) {
								menuSpan = em.find('span:first');
							}else{
								menuSpan = em;
							}
							
							
							// 如果是盒子
							if (menuSpan.attr('id').indexOf('_box')>0) {
								var bbId = menuSpan.attr('id').replace('_box','');
								var bbname = menuSpan.text();
								swal({
									title: '编辑书签目录',
									html: '<input id="swal-input1" name="bbname" class="swal2-input" placeholder="目录名:" value='+ bbname +'  required> <a href="javascript:input1ToEmpty()" class="clear"></a>',
									preConfirm: function() {
										return new Promise(function(resolve) {
											resolve([
												$('#swal-input1').val(),
											]);
										});
									}
								}).then(function(result) {

									if(result != "") {
										
										$.post("http://"+lh+"/time/edit_bbname.action", { "id": bbId, "bbname": result[0] }, function(data) {

											swal({
												type: 'success',
												title: 'Good job',
												allowOutsideClick: true,
												showConfirmButton: false,
												timer: 1000
											});
											
											setTimeout(function(){location.reload([false])}, 1000);
										});
										
									}
								});
								
								// input输入框获取光标
								var t=$("#swal-input1").val(); 
								$("#swal-input1").val('').focus().val(t); 
								
							}else if(!isNaN(menuSpan.attr('id'))){
								swal({
									title: '编辑书签',
									html: '<input id="swal-input1" class="swal2-input" placeholder="书签名:" value='+ menuSpan.text() +'  required>  <a href="javascript:input1ToEmpty()" class="clear"></a>     <input id="swal-input2"  class="swal2-input c2" value='+ menuSpan.parent().attr('href') +' placeholder="网址:"   required>   <a href="javascript:input2ToEmpty()" class="clear2"></a> ',
									preConfirm: function() {
										return new Promise(function(resolve) {
											resolve([
												$('#swal-input1').val(),
												$('#swal-input2').val()
											]);
										});
									}
								}).then(function(result) {
									
									// 补全路径
									if(result[1].substring(0, 4) != "http") {
										result[1] = "http://" + result[1];
									}

									menuSpan.text(result[0]);
									menuSpan.parent().attr('href',result[1]);
										
											
									// 同步到服务器
									$.post("http://"+lh+"/time/edit_bookmark.action", { "id": menuSpan.attr('id'), "bname": result[0] , "url": result[1]}, function(data) {

										swal({
											type: 'success',
											title: 'Good job',
											allowOutsideClick: true,
											showConfirmButton: false,
											timer: 1000
										});
										
										setTimeout(function(){location.reload([false])}, 1000);
									});
									
								});
								
								var t=$("#swal-input1").val(); 
								$("#swal-input1").val('').focus().val(t); 
								
							}
							
						}
					}, {
				        type: "item",
				        icon: "scissors",
				        text: "删除书签",
				        key: "cut",
				        action: function(){
				        	if (loginCheck() != "login") {
								return;
							}
				        	
				        	var menuSpan;
							if (em.attr('id') == undefined) {
								menuSpan = em.find('span:first');
							}else{
								menuSpan = em;
							}
							
							if (menuSpan.attr('id')=="") {
								return;
							}
							
							
							if (menuSpan.attr('id').indexOf('_box')>0) {
								
								// 防止用户误操作导致删除书签盒子
								swal({
									  title: '确定删除书签盒子?',
									  text: "这将使您失去盒子及里面的所有书签",
									  type: 'warning',
									  showCancelButton: true,
									  confirmButtonColor: '#d33',
									  cancelButtonColor: '#3085d6',
									  cancelButtonText: '取消',
									  confirmButtonText: '删除'
									}).then(function(isConfirm) {
									  if (isConfirm) {

										var bbId = menuSpan.attr('id').replace('_box','');
										
										// 同步到服务器
										$.post("http://"+lh+"/time/del_bb.action", { "id": bbId }, function(data) {

											swal({
												type: 'success',
												title: 'Good job',
												allowOutsideClick: true,
												showConfirmButton: false,
												timer: 1000
											});
											
											setTimeout(function(){location.reload([false])}, 1000);
										});
									  }
								});
								
								
								
							}else if(!isNaN(menuSpan.attr('id'))){
								// 时间书签的子项不会被删除
								if (menuSpan.attr('class') == 'timeB') {
									return ;
								}
								
								// 同步到服务器
								$.post("http://"+lh+"/time/del_bookmark.action", { "id": menuSpan.attr('id') }, function(data) {

									swal({
										type: 'success',
										title: 'Good job',
										allowOutsideClick: true,
										showConfirmButton: false,
										timer: 1000
									});
									
									setTimeout(function(){location.reload([false])}, 1000);
								});
								
							}
				        	
				        	
				        }
				    }
					
				];

				$(window).contextMenu({

					items: _menuItems
				});

			});

			function addBookMark() {
				$("#dialog-form").dialog("open");
			}
			
			
			
			// 清空输入框兼容两个input同时存在
			function input1ToEmpty() {
				$('#swal-input1').val('');
			}			
			function input2ToEmpty() {
				$('#swal-input2').val('');
			}

			function addBookMark(obj) {
				if ($(obj).is('a')) {
					obj = obj.parent().parent().parent().find("span:first").text();
				}
				
				swal({
					title: '添加书签',
					html: '<input id="swal-input1" class="swal2-input" placeholder="书签名:"   required>  <a href="javascript:input1ToEmpty()" class="clear"></a>     <input id="swal-input2"  class="swal2-input c2"  placeholder="网址:" required>   <a href="javascript:input2ToEmpty()" class="clear2"></a> ',
					confirmButtonText: '添加',
					preConfirm: function() {
						return new Promise(function(resolve) {
							resolve([
								$('#swal-input1').val(),
								$('#swal-input2').val()
							]);
						});
					}
				}).then(function(result) {
					// 补全路径
					if(result[1].substring(0, 4) != "http") {
						result[1] = "http://" + result[1];
					}

					// 同步到服务器
					$.post("http://"+lh+"/time/add_bb.action", {"user.id":user.id, "bbname": obj, "bname": result[0], "burl": result[1] }, function(data) {

						swal({
							type: 'success',
							title: 'Good job',
							allowOutsideClick: true,
							showConfirmButton: false,
							timer: 1000
						});
						
						setTimeout(function(){location.reload([false])}, 1000);
						
					});
				});
				
				$("#swal-input1").focus(); 
			};
			
			
			function delBg(){
				if (loginCheck() != "login") {
					return;
				}
				
				if (pictures.length > 1) {
					var v = pictures.splice(index,1);
					index = index - 1;
					
					pageTurn('down');
					$.post('http://'+lh+'/time/user_delBg.action',{'bgSrc':v[0]});
					
				}else if(pictures.length == 1){
					swal('这是最后一张图片了')
				}
				
				
				/*else {
					var v = Math.floor(Math.random()*(10-1)+1);
					$("#bg").attr("src","/time/parent-time/everyday/img/back("+ v +").png");
				}*/
				
			}
			

			function addBookMark_Box() {
				if (loginCheck() != "login") {
					return;
				}
				
				swal({
					title: '添加书签目录',
					html: '<input id="swal-input1" name="bbname" class="swal2-input" placeholder="目录名:" required>   <a href="javascript:input1ToEmpty() " class="clear"></a>  <span style="float:left" > 确定后请添加一个书签,这将为您同步到云端 </span> <br/><br/>',
					confirmButtonText: '确定',
					preConfirm: function() {
						return new Promise(function(resolve) {
							resolve([
								$('#swal-input1').val(),
							]);
						});
					}
				}).then(function(result) {
					
					addBookMark(result[0]);
				});
				
				$("#swal-input1").focus(); 
			};


			function showTime() {
				var time = new Date();
				var yyyy = time.getFullYear();
				var MM = time.getMonth() + 1;
				var dd = time.getDate();
				var HH = time.getHours();
				var mm = time.getMinutes();
				var ss = time.getSeconds();
				
				a.innerHTML = yyyy + "&nbsp;-";
				b.innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp" + MM + "&nbsp;-";
				c.innerHTML = "&nbsp;&nbsp;&nbsp;" + dd;
				d.innerHTML = HH + "&nbsp:";
				if(mm < 10) {
					mm = "0" + mm;
				}
				if(ss < 10) {
					ss = "0" + ss;
				}
				e.innerHTML = mm + "&nbsp:";
				f.innerHTML = ss;
				//	v.innerHTML=yyyy+"年"+MM+"月"+dd+"日"+HH+"时"+mm+"分"+ss+"秒";
			}

			function timeToLoad() {
				// $("#nyr,#sfm").slideDown(2000);
				// $("#nyr,#sfm").css('display','block');
			}
			
			var tempA = 1;
			function timeToHidden(v) {
				if (tempA == 1) {
					$("#nyr,#sfm").hide();
					tempA = tempA - 1;
					$(v).children('span').html('显示时间');
				}else {
					$("#nyr,#sfm").show();
					tempA = tempA + 1;
					$(v).children('span').html('隐藏时间');
				}
			}

			function prefer() {
				if (loginCheck() != "login") {
					return;
				}
				
				var preferImg = $('#divBody').css("background-image");
				console.log(preferImg);
				preferImg = preferImg.substr(preferImg.indexOf('/time'),preferImg.length);
				preferImg = preferImg.substr(0,preferImg.length-2);
				console.log(preferImg);
				$.post("http://"+lh+"/time/user_perfer.action", { 'prefer':  preferImg}, function(data) {
					swal({
						type: 'success',
						title: 'Good job',
						allowOutsideClick: true,
						showConfirmButton: false,
						timer: 1000
					});
				});
			}

			// 判断数组中的字符串是否含有指定串
			var myInArray = function(arr, item) {
				for(var i = 0; i < arr.length; i++) {
					if(arr[i].indexOf(item) >= 0) {
						console.log('找到了');
						return i;
					}
				}
				return 1;
			};

			// 背景图翻页
			function pageTurn(v) {
				if(v == 'up') {
					// 用户看到首张,自动跳到末张
					if(index == 0) {
						index = pictures.length - 1;
					} else {
						index -= 1;
					}
					
					var img = new Image();
					img.src = pictures[index];
					if (!img.complete) {

						$("#container").css('display','block');
						img.onload = function(){
							$("#container").css('display','none');
						};
					}
						
					$("#divBody").css("background-image", "url('"+pictures[index]+"')");
					pullImg();
					return ;
				}

				if(v == 'down') {
					// 用户看到末张,自动跳到首张
					if(index == pictures.length - 1) {
						index = 0;
					} else {
						index += 1;
					}
					
					var img = new Image();
					img.src = pictures[index];
					if (!img.complete) {

						$("#container").css('display','block');
						img.onload = function(){
							$("#container").css('display','none');
						};
					}
					
					$("#divBody").css("background-image", "url('"+pictures[index]+"')");
					pullImg();
					return ;
				}
			}
			

			
			
			function loginCheck(url) {
				if (user.username == 'admin') {
					swal({
						  title: '您还没有登录',
						  text: "是否现在登录",
						  type: 'warning',
						  showCancelButton: true,
						  confirmButtonText: '是的,去登陆',
						}).then(function(isConfirm) {
						  if (isConfirm) {
							  window.location.href="http://"+lh+"/time/user/login.html";
						  }
					})
					return;
				}
				
				if (url == null) {
					return "login";
				}else {
					window.open(url);
					return;
				}
				
			};
			
			// 页面加载拉取更多
			function pullImg(){
				var img = new Image();
				img.src = pictures[index];
				
				img.onload = function(){
					
					var img1 = new Image();
					var img2 = new Image();
					var img3 = new Image();
					var img4 = new Image();
					if (index == 0) {
						img1.src = pictures[index+1];
						img2.src = pictures[index+2];
						img3.src = pictures[pictures.length-1];
						img4.src = pictures[pictures.length-2];
					}
					
					if (index == 1) {
						img1.src = pictures[index+1];
						img2.src = pictures[index+2];
						img3.src = pictures[index-1];
						img4.src = pictures[pictures.length-1];
					}
					
					if (index == pictures.length-1) {
						img1.src = pictures[0];
						img2.src = pictures[1];
						img3.src = pictures[index-1];
						img4.src = pictures[index-2];
					}
					
					if (index == pictures.length-2) {
						img2.src = pictures[0];
						img1.src = pictures[index+1];
						img3.src = pictures[index-1];
						img4.src = pictures[index-2];
					}
					
					if (index > 1 && index < pictures.length-2) {
						img1.src = pictures[index-1];
						img2.src = pictures[index-2];
						img3.src = pictures[index+1];
						img4.src = pictures[index+2];
					}
					
					
				};
					
				
				
				// 背景加载过渡
				
			};
			
			
			// 过渡界面判断
			function interim(eqimg){
				setTimeout(function() {
					
					if (!eqimg.complete) {
						$('#divBody').css('display','block');
						$('#container,#saying').css('display','block');
						eqimg.onload = function(){
							$('#container,#saying').css('display','none');
							$("#divBody").css('display','none');
							$("#divBody").fadeIn(2000);
							$("#divBody").css("background-image", "url('"+pictures[0]+"')");
							pullImg();
						}
					}else {
						alert('有缓存');
						$("#divBody").css('display','none');
						$("#divBody").fadeIn(2000);
						$("#divBody").css("background-image", "url('"+pictures[0]+"')");
						pullImg();
					}
					
				}, 200);
				
			};
			
			
			// 先前使用监控浏览器大小适应背景图片缩放，发现使用css就可以实现
			/*window.onresize = function(){
				if(document.documentElement.clientHeight < 650){
					$("#divBody").css("background-size","100% 100%")
				}
				
				if(document.documentElement.clientHeight > 700){
					$("#divBody").css("background-size","118% 100%")
				}
				// document.getElementById("info_jb51_net").innerHTML="宽度："+document.documentElement.clientWidth+"，高度："+document.documentElement.clientHeight;
			};*/
			
/*			function kaishi() {

				var docElm = document.documentElement;
				//W3C   
				if(docElm.requestFullscreen) {
					docElm.requestFullscreen();
				}
				//FireFox   
				else if(docElm.mozRequestFullScreen) {
					docElm.mozRequestFullScreen();
				}
				//Chrome等   
				else if(docElm.webkitRequestFullScreen) {
					$("#divBody").css("background-size","118% 100%");
					
					docElm.webkitRequestFullScreen();
				}
				//IE11   
				else if(elem.msRequestFullscreen) {
					elem.msRequestFullscreen();
				}
			}

			function guanbi() {

				if(document.exitFullscreen) {
					document.exitFullscreen();
				} else if(document.mozCancelFullScreen) {
					document.mozCancelFullScreen();
				} else if(document.webkitCancelFullScreen) {
					document.webkitCancelFullScreen();
				} else if(document.msExitFullscreen) {
					document.msExitFullscreen();
				}
			}

			document.addEventListener("fullscreenchange", function() {

				fullscreenState.innerHTML = (document.fullscreen) ? "" : "not ";
			}, false);

			document.addEventListener("mozfullscreenchange", function() {

				fullscreenState.innerHTML = (document.mozFullScreen) ? "" : "not ";
			}, false);

			document.addEventListener("webkitfullscreenchange", function() {

				fullscreenState.innerHTML = (document.webkitIsFullScreen) ? "" : "not ";
			}, false);

			document.addEventListener("msfullscreenchange", function() {

				fullscreenState.innerHTML = (document.msFullscreenElement) ? "" : "not ";
			}, false);
			*/